# 第1，2题
people<-c("o","m","y","m","y","m","o","y","m","o")
age<-c(86,34,21,45,23,41,73,16,31,78)
tapply(age,people,mean)

weight<-c(73,55,58,64,72,67,54,80,79,61)
height<-c(155,169,173,146,175,178,165,159,173,171)
data1<-data.frame(people,age,weight,height)


# 3.文件读入读出
setwd("C:\\Users\\lenovo\\Desktop\\")  #修改为目标文件所在路径
a=read.table("ADdata1.txt")    #以下打开各种数据
b=read.csv("ADdata2.csv")
library("openxlsx")     #加载包
c=read.xlsx("ADdata3.xlsx")
d=read.table("ADdata4.txt")

X=rownames(a)    #提取行名作为第一列
a2=cbind(X,a)
mer1=merge(a2,b,by=intersect(names(a2),names(b)))   #合并
names(c)[1]<-"X"    #给第一列命名
mer2=merge(mer1,c,by=intersect(names(mer1),names(c)))
X=rownames(d)    
d1=cbind(X,d)
mer3=merge(mer2,d1,by=intersect(names(mer2),names(d1)))
write.csv(mer3,file="merdata.csv",row.names = FALSE)   #保存为csv格式
write.xlsx(mer3,file="merdata1.xlsx",rowNames = FALSE) #保存为xlsx格式
sink(file="merdata2.txt")    #保存为txt格式
mer3
sink()